# リファクタリング前
class Game

  def initialize
    @rolls = []
  end

  def roll(pins)
    @rolls << pins
  end

  def score
    roll_idx = 0
    score = 0
    
    10.times do |frame|
      # strike?
      if @rolls[roll_idx] == 10
        # strike
        score += 10 + @rolls[roll_idx + 1] + @rolls[roll_idx + 2]
        roll_idx += 1
      # spare?
      elsif @rolls[roll_idx] + @rolls[roll_idx + 1] == 10
        # spare
        score += 10 + @rolls[roll_idx + 2]
        roll_idx += 2
      else
        score += @rolls[roll_idx] + @rolls[roll_idx + 1]
        roll_idx += 2
      end
    end
    
    score
  end
end